package Day2025_02_24;

public class LeetCode238 {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] arr = new int[n];
        int[] dp1 = new int[n + 1];
        int[] dp2 = new int[n + 1];
        dp1[0] = dp2[0] = 1;
        for (int i = 1; i <= n; i++) {
            dp1[i] = dp1[i - 1] * nums[i - 1];
            dp2[i] = dp2[i - 1] * nums[n - i];
        }
        for (int i = 1; i <= n; i++) arr[i - 1] = dp1[i - 1] * dp2[n - i];
        return arr;
    }
}
